﻿#if NETCOREAPP3_0
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Bootstrap.Security.Mvc.Controller
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        [AllowAnonymous]
        [HttpGet]
        public string Get(string userName)
        {
            return userName;
        }

        [HttpPost]
        public bool Post(PostData postData)
        {
            return User.IsInRole(postData.RoleName);
        }

        [AllowAnonymous]
        [HttpPut]
        [ButtonAuthorize(Url = "/api/Test", Auth = "put")]
        public bool Put()
        {
            return true;
        }

        [AllowAnonymous]
        [HttpDelete]
        [ButtonAuthorize(Url = "/api/Test", Auth = "del")]
        public bool Delete()
        {
            return true;
        }
    }

    public class PostData
    {
        public string RoleName { get; set; }
    }

    public class HomeController : Microsoft.AspNetCore.Mvc.Controller
    {
        [HttpGet]
        public ActionResult Index(string queryData)
        {
            return new ContentResult() { Content = queryData };
        }
    }
}
#endif
